<?php
use yii\helpers\Url;
use yii\Web\View;
use app\assets\NewAdvertiserAsset;
NewAdvertiserAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => \Yii::t('advertiser', 'Brand'),
    'url' => ['brand-list']
  ],
  \Yii::t('advertiser', 'Edit Brand')
];
$jsMsgs = $this->context->loadJsMsgs([
  'listOp',
  'brandForm'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('advertiser', 'Brand')?>
    <small><?=\Yii::t('advertiser', 'Edit Brand')?></small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-edit"></i>
    <?=\Yii::t('advertiser', 'Edit Brand')?>
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
  <div class="panel-body">
    <div class="row">
      <div class="col-sm-8 col-sm-offset-2">
        <form class="form-horizontal" id="data-frm" method="POST" action="<?php echo Url::to(['brand/brand-edit-handle']);?>">
          <input class="hidden" type="text" name="id" value="<?= $advertiser['id'] ?>">
          <fieldset>
            <legend><?=\Yii::t('advertiser', 'Basic Info')?></legend>
            <div class="form-group">
              <label class="col-sm-2 control-label pl0" for="advertiser_name" >
                <em>*</em>
                <?=\Yii::t('advertiser', 'Name')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="advertiser_name" type="text" name="name" value="<?= $advertiser['name'] ?>" placeholder="<?=\Yii::t('advertiser', 'Brand Name')?>">
                <div class="help-block text-error" id="advertiser_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="creative_vocation" >
                <em>*</em>
                <?=\Yii::t('advertiser', 'Vocation')?>：
              </label>
              <div class="col-sm-5">
                <select class="form-control" id="creative_vocation_large" name="parent_category"></select>
              </div>
              <div class="col-md-5">
                <select class="form-control" id="creative_vocation_small" name="category"></select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="recharge_amount">
                <?=\Yii::t('advertiser', 'Balance')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="recharge_amount" type="text" name="total_budget" value="<?= $advertiser['total_budget'] ?>" placeholder="0.00">
                <div class="help-block text-error" id="recharge_amount_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="website_name">
                <em>*</em>
                <?=\Yii::t('advertiser', 'Web Name')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="website_name" type="text" name="site" value="<?= $advertiser['site'] ?>" placeholder="">
                <div class="help-block text-error" id="website_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="website_url_url">
                <em>*</em>
                <?=\Yii::t('advertiser', 'Website')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="website_url" type="text" name="adomain" value="<?= $advertiser['adomain'] ?>" placeholder="http(s)://">
                <div class="help-block text-error" id="website_url_err"></div>
              </div>
            </div>
          </fieldset>
          <!-- <fieldset>
            <legend>转化设置</legend>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="click_monitor_url" >
                转化名称：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="transform_name" type="text" name="convertion_name" value="<?= $advertiser['convertion_name'] ?>" placeholder="">
                <div class="help-block text-error" id="transform_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label pl0" for="transform_belong_method">
                转化归属方法：
              </label>
              <div class="col-sm-10">
                <select class="form-control" id="transform_belong_method" name="conversion_vest_method">
                  <option value="1" <?php if($advertiser['conversion_vest_method']==1) echo "selected"; ?> >最后一次点击</option>
                  <option value="2" <?php if($advertiser['conversion_vest_method']==2) echo "selected"; ?> >最后一次曝光</option>
                  <option value="3" <?php if($advertiser['conversion_vest_method']==3) echo "selected"; ?> >最后一次曝光和点击</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="belong_deadline" >
                归属期限：
              </label>
              <div class="col-sm-5">
                <input class="form-control" id="belong_deadline" type="text" name="click_vest_day" value="<?= $advertiser['click_vest_day'] ?>" placeholder="30">
                <div class="help-block text-error" id="belong_deadline_err"></div>
              </div>
              <div class="col-sm-5 pl0">
                <p class="form-control-static">(距点击天数，最多30天)</p>
              </div>
            </div>
          </fieldset> -->
          <fieldset>
            <legend><?=\Yii::t('advertiser', 'Contact Info')?></legend>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="website_contacter">
                <em>*</em>
                <?=\Yii::t('advertiser', 'Contactor')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="website_contacter" type="text" name="contactor" value="<?= $advertiser['contactor'] ?>" placeholder="">
                <div class="help-block text-error" id="website_contacter_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="email_address">
                <em>*</em>
                <?=\Yii::t('advertiser', 'Email')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="email_address" type="text" name="email" value="<?= $advertiser['email'] ?>" placeholder="example@example.com">
                <div class="help-block text-error" id="email_address_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="cellphone_number">
                <em>*</em>
                <?=\Yii::t('advertiser', 'Mobile')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="cellphone_number" type="text" name="mobile" value="<?= $advertiser['mobile'] ?>" placeholder="">
                <div class="help-block text-error" id="cellphone_number_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="telephone_number">
                <em>*</em>
                <?=\Yii::t('advertiser', 'Tel')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="telephone_number" type="text" name="phone" value="<?= $advertiser['phone'] ?>" placeholder="">
                <div class="help-block text-error" id="telephone_number_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <legend><?=\Yii::t('advertiser', 'Bind User')?></legend>
             <div class="form-group">
              <label class="col-sm-2 control-label" for="bind_users">
                <?=\Yii::t('advertiser', 'Choose User')?>：
              </label>
              <div class="col-sm-10">
              <select class="form-control" id="bind_users" name="bind_users[]" placeholder="<?=\Yii::t('advertiser', 'Choose User')?>" multiple>
              <?php
                $out = '';
                $Ids = array_column($bindUsers, 'user_id');
                foreach ($operators as $id => $operator) {
                  $name = $operator['name'];
                  $selected = '';
                  if (in_array($id, $Ids)) $selected = "selected";
                  $out .= <<<FINE
                        <option value='$id' $selected >$name</option>
FINE;
                }
                echo $out;
              ?>
            </select>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10 col-xs-offset-3 col-xs-6">
                <div class="btn-form-group pull-right">
                  <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
                  <a href="<?php echo Url::to(['brand/brand-list']); ?>" class="btn btn-default"><?=\Yii::t('common', 'Back')?></a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>
<?php
  //$creativeVocation = '{"汽车":["车讯行情","车辆养护","配件改装","其它"],"新闻":["军事","时政要闻","产经","科技","其它"],"财经":["股票","基金","理财","房产","保险","收藏","其它"],"数码":["电脑","手机","数码设备","软件","APP","其它"],"医疗":["健康养生","疾病治疗","整形美容","两性","其它"],"娱乐影音":["影视","音乐","图书","图片","星座","明星","游戏","宠物","休闲活动","其它"],"社交与网络服务":["婚恋交友","SNS","论坛","网络服务"],"教育":["幼教","应试","考研","培训","MBA","出国","自考","其它"],"家居家电":["家电","家具","装修","装饰","日常用品"],"体育":["足球","篮球","网球","户外","健身","器材","其它"],"旅行":["酒店和住宿","旅行社和服务","票务服务"],"女性":["时尚","美容","母婴"],"职业":["简历","招聘信息","其它"],"食品饮料":["美食","零食","饮料","烟酒","保健食品","其它"],"服饰鞋包":["服装","鞋靴","配饰","珠宝首饰","箱包","钟表","奢侈品","眼镜"],"工农业":["电子电工","机械设备","农林牧渔","化工及材料"],"生活和商务服务":["生活服务","商务服务"]}';
  $creativeVocation = $categories;  
  $parentCategory = array_shift($category);
  $childCategory = array_shift($category);
  $this->registerJs("VAM.setVar('CREATIVE_VOCATION','$creativeVocation')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('parent_category','$parentCategory')", View::POS_END);
  $this->registerJs("VAM.setVar('child_category','$childCategory')", View::POS_END);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/brand/newBrand.js"]);
  });
</script>